<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改配额</title>
    <script src="jquery/jquery-3.3.1.min.js"></script> <!-- 你必须先引入jQuery1.8或以上版本 -->
    <link rel="stylesheet" href="zTree/layui/css/layui.css">
    <style type="text/css">
        .layui-form{
            margin: 10%;
        }
    </style>
</head>
<body>
<div class="frame">
    <form class="layui-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
        <div class="layui-form-item">
            <label class="layui-form-label">实例数</label>
            <div class="layui-input-block">
                <select name="instance" lay-filter="*" lay-search required lay-verify="required">
                    <option value="">请选择要增加或削减的实例数量</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">VCPU数量</label>
            <div class="layui-input-block">
                <select name="vcpu" lay-filter="*" lay-search required lay-verify="required">
                    <option value="">请选择要增加或削减的VCPU数量</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">内存大小</label>
            <div class="layui-input-block">
                <select name="ram" lay-filter="*" lay-search required lay-verify="required">
                    <option value="">请选择要增加或削减的内存大小</option>
                    <option value="128">128MB</option>
                    <option value="250">256MB</option>
                    <option value="512">512MB</option>
                    <option value="1024">1024MB</option>
                    <option value="2048">2048MB</option>
                    <option value="4096">4096MB</option>
                    <option value="8192">8192MB</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">硬盘大小</label>
            <div class="layui-input-block">
                <select name="disk" lay-filter="*" lay-search required lay-verify="required">
                    <option value="">请选择要增加或削减的内存大小</option>
                    <option value="10">10GB</option>
                    <option value="20">20GB</option>
                    <option value="40">40GB</option>
                    <option value="80">80GB</option>
                    <option value="160">160GB</option>
                    <option value="320">320GB</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">添加或者削减</label>
            <div class="layui-input-block">
                <input type="radio" name="isAdd" value="true" title="添加">
                <input type="radio" name="isAdd" value="false" title="削减" checked>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formSubmit">立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="zTree/layui/layui.js"></script>
<script src="zTree/layer/layer.js"></script>
<script>
    index = parent.layer.getFrameIndex(window.name);//通过父窗体的layer获得当前窗体的索引
    layui.use('form', function() {
        var form = layui.form;
        //监听提交
        form.on('submit(formSubmit)', function (data) {
            var instance = data.field.instance;
            var vcpu = data.field.vcpu;
            var ram = data.field.ram;
            var disk = data.field.disk;
            var isAdd = data.field.isAdd;
            $.ajax({
                url: "instance/changeUserQuota",
                type: "POST",
                data: {
                    instance:instance,
                    vcpu:vcpu,
                    ram:ram,
                    disk:disk,
                    isAdd:isAdd
                },
                dataType: "text",
                success: function (result) {
                    if(result==="200"){
                        parent.layer.close(index);
                        parent.layer.msg("更新配额成功!", {
                            icon:6,//笑脸
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        });
                    }else if(result==="400"){
                        layer.msg("您要削减的配额大于总配额!请重新输入", {
                            icon:6,//笑脸
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        });
                    }else {
                        parent.layer.close(index);
                        parent.window.location.href="login";
                    }
                }
            });
        });
    });
</script>
</body>
</html>